<%- include fheader.ejs %>
<style>
    body {
        color: #333;
        font-size: 16px !important;
    }

    .ui-dialog-bd div {
        text-align: center;
    }

    .wrp {
        padding: 10px 0;
        position: relative;
    }

    .wrp ul {
        margin-bottom: 15px
    }

    .cardNo {
        color: #ff5c01;
        font-size: 20px;
        padding-right: 5px
    }

    .ui-list-info p.gray {
        color: #999
    }

    .statusShow {
        color: #1ea5f5;
        font-size: 12px;
        border: 1px solid #1ea5f5;
        border-radius: 20px;
        padding: 2px 5px;
    }

    .ui-btn, .ui-btn:focus, .ui-btn:not(.disabled):not(:disabled):active, .ui-btn.active {
        background-color: #1ea5f5;
        border-color: #1ea5f5;
        background-image: none;
        color: white;
    }

    .ui-btn:focus, .ui-btn:not(.disabled):not(:disabled):active, .ui-btn.active {
        background-color: #0b7bbd;
        border-color: #0b7bbd;
    }

    .ui-dialog .ui-btn-group button {
        background-color: inherit !important;
        color: #00a5e0;
        border-radius: inherit;
    }

    p {
        margin: 0 !important
    }
</style>
<link rel="stylesheet" href="/wx/css/sm.min.css">
<script src="/wx/js/sm.min.js"></script>

<section class="ui-container">
    <div class="ui-scroller" style="margin-top:10px;overflow: hidden">
        <div class="wrp" id="cardHis" style="margin-bottom: 10px;">
        </div>
        <div style="margin: 30px 0 0; position:fixed; bottom:0; left:0; z-index: 10;width:100%">
            <a data-href="/rest/svcWxPage/custLogout" id="btnLogout" style="background: #fff;color: #18b4ed;border: 1px solid #18b4ed;" class="ui-btn ui-btn-lg ui-btn-primary">
                退出登录
            </a>
        </div>
    </div>
</section>
<script type="tmpl/text" id="jstmpl">
{{for(var i in it){}}
     <ul class="ui-list ui-list-text">
         <li class="ui-border-t">
             <div class="ui-list-info">
             <h4><span>保单号  </span><span class="cardNo">{{=it[i]['insure_id']}}</span></h4>
             <p class="gray">有效期: <span>{{=(it[i]['workdate']+' 至 '+it[i]['invaliddate'])}}</p>
             <p class="gray">用户电话: <span> {{=it[i]['cellno']}}</span></p>
             {{if(it[i]['insure_id']){}}
             <p class="gray">机型: <span> {{=it[i]['modal_dtl']}}</span></p>
             {{}}}
             {{if(it[i]['pay_type']){}}
             <p class="gray">支付方式: <span> {{=PAY_MAP[it[i]['pay_type']]}}</span></p>
             {{}}}
             </div>
             <div class="ui-list-action statusShow">{{=STAT_MAP[it[i]['state']]}}</div>
         </li>
         {{if(it[i]['verifydone']=='1' && it[i]['cstate']=='1'){}}
                 <li class="ui-border-t">
                     <div class="ui-flex ui-txt-info ui-flex-pack-end">
                         <button class="ui-btn changeCard" data-otn="{{='s_'+it[i]['out_trade_no']}}">申请理赔</button>
                         <input type="hidden" class="udid" data-udid="{{='s_'+it[i]['udid']}}">
                         <input type="hidden" class="imei" data-imei="{{='s_'+it[i]['imei']}}">
                         <input type="hidden" class="insure_id" data-insure_id="{{='s_'+it[i]['insure_id']}}">
                         </div>
                 </li>
         {{}}}
     </ul>
{{}}}

</script>
<script>
    $("#sdate").calendar();
    $("#edate").calendar();

    var STAT_MAP = {
        0: '审核中',
        1: '生效中',
        2: '已过期',
        3: '申请理赔',
        4: '理赔受理',
        5: '维修完成',
        6: '理赔完成',
        7: '失效',
        8: '取消',
        9: '退款'
    };
    var PAY_MAP = {1: '扫码支付', 2: '店员代付',3:'线下支付'};

    $(function () {
        var PROD_LIST_URL = '/rest/svcApplyIns/mGetCustOrderListByCellno';
        var GET_QRCODE_URL = '/rest/svcLipeiIns/mWxdCompensateGetQRCodeByUDIDandInsureId';

        var cellno = '<%= cellno%>';
        var scroll = null;

        function loadData() {
            var p = {
                cellno: cellno,
                fdval:cellno,
                fd:'cellno'
            };
            juq.showLoading();
            juq.fpost(PROD_LIST_URL, p, function (data) {

                juq.hideLoading();
                if (data.length <= 0) {
                    $('#cardHis').html('<div class="ui-tips ui-tips-info"> <i></i><span>暂时还没有记录</span> </div>');
                    return;
                }
                    var html = $('#jstmpl').tmpl(data);
                    $('#cardHis').html(html);
                    scroll && scroll.refresh();
                });
        }

        $('#cardHis').on('click', '.changeCard', function () {
            var $parent = $(this).parents('li');

            var imei =  $parent.find('.imei').data('imei').substr(2);
            var insure_id = $parent.find('.insure_id').data('insure_id').substr(2);
            var udid =$parent.find('.udid').data('udid').substr(2);

            var param = {
                imei:imei,
                insure_id:insure_id,
                udid:udid
            }

            console.log(param);

            juq.fpost(GET_QRCODE_URL, param, function(qdata){

                var qrcode = qdata;
                location.href = '/rest/svcWxPage/claim?qscode=' + qrcode;
            },function (res, info){
                juq.hideLoading();
                juq.showLoading;

            });
        });

        $('#btnLogout').tap(function() {
            var $this = $(this);
            var dia = $.dialog({
                title: '',
                content: '确认要退出吗?',
                button: ["确认", "取消"]
            });

            dia.on("dialog:action", function (e) {
                if (e.index == 0) {
                    location.href = $this.data('href');
                }
            });
        });


        $('.ui-scroller').css('height', $(window).height()-$('#topForm').height()-$('#navbar').height()-20);
        scroll = new fz.Scroll('.ui-scroller', {scrollY: true})
        loadData();
    });
</script>

<%- include ftailer.ejs %>
